<template>
  <div>
    <div>
      <Button type="primary" @click="add">新增</Button>
    </div>
    <Table border :columns="columns12" :data="data">
      <template slot-scope="{ row }" slot="name">
        <strong>{{ row.name }}</strong>
      </template>
      <template slot-scope="{ row, index }" slot="action">
        <Button type="primary" size="small" style="margin-right: 5px" @click="show(row)">编辑</Button>
        <Button type="error" size="small" @click="remove(row)">删除</Button>
      </template>
    </Table>
    <el-dialog :visible.sync="addNotice" v-if="addNotice" :close-on-click-modal="false">
      <addNotice @after="getNotice" @hideenDialog="hidden" ></addNotice>
    </el-dialog>
    <el-dialog :visible.sync="updateNotice" v-if="updateNotice" :close-on-click-modal="false">
      <UpdateNotice @after="getNotice" :Data="Data" @hideDialog="hidden" ></UpdateNotice>
    </el-dialog>
  </div>
</template>


<script>
import addNotice from "_c/Notice/addNotice";
import UpdateNotice from "_c/Notice/UpdateNotice";
export default {
  name: "announcement",
  components:{addNotice,UpdateNotice},
  data () {
    return {
      addNotice:false,
      updateNotice:false,
      columns12: [
        {
          title: '公告',
          key: 'content'
        },
        {
          title: '发布时间',
          key: 'create_date'
        },
        {
          title: '发布人',
          key: 'author'
        },
        {
          title: '操作',
          slot: 'action',
          width: 150,
          align: 'center'
        }
      ],
      data: []
    }
  },
  methods: {
    show (row) {
       this.Data=row
       this.updateNotice=true
    },
    remove (row) {
        this.$confirm("确定要删除吗","提示").then(()=>{
          this.http.post("/deleteNotice",this.qs.parse(row)).then(res=>{
            if (res.data){
              this.$Message.success("删除成功")
              this.getNotice();
            }else {
              this.$Message.error("删除失败")
            }
          })
        })
    },
    add(){
      this.addNotice=true
    },
    getNotice(){
      this.http.get("/getNotice").then(res=>{
        if (res.data){
          this.data=res.data
        }
      })
    },
    hidden(){
      this.addNotice=false;
      this.updateNotice=false;
    }
  },
  created() {
    this.getNotice();
  }
}
</script>

<style scoped>

</style>
